<script setup lang="ts">
import {ref} from 'vue'
import AddPost from '../post/AddPost.vue'
import { useRouter } from 'vue-router'
import { useUserStore } from '@/stores/user'

const userStore = useUserStore()
const yhm=userStore.yhm;
console.log(yhm);
const isLoggedIn =ref(userStore.isLoggedIn);
const handleSelect = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}
const router = useRouter()
const addDialogVisible=ref(false);
const showAdd = () => {
  if(isLoggedIn.value){
    addDialogVisible.value=true;
  }else{
    router.push('/login');
  }

}
import {
  Search,
  HomeFilled,
  Star,
  VideoPlay,
  Message,
  MoreFilled, Setting
} from '@element-plus/icons-vue'
const tx = ref('https://tvax1.sinaimg.cn/crop.0.0.1080.1080.180/0086eF7Vly8h6lg9cm5wnj30u00u0ab8.jpg?KID=imgbed,tva&Expires=1752993846&ssig=Y8W%2FvmEB%2F2')
</script>

<template>

  <div class="navbar-container">
    <el-row class="navbar" justify="space-between" align="middle">
      <!-- 左侧部分 -->
      <el-col :span="4" class="left-section">
        <div class="logo-area">
          <el-icon size="24" color="red">
            <!-- 这里放微博图标，实际项目中替换为微博图标组件 -->
            <component :is="'el-icon-platform-eleme'" />
          </el-icon>
          <span class="logo-text">博客</span>
        </div>
      </el-col>

      <!-- 中间部分 -->
      <el-col :span="12" class="center-section">
        <el-input
            class="search-input"
            placeholder="搜索微博"
            :prefix-icon="Search"
        />
      </el-col>

      <!-- 右侧部分 -->
      <el-col :span="8" class="right-section">
        <div class="nav-items">
          <el-button class="bu" v-if="isLoggedIn">
            <span>{{yhm}}</span>
            <el-avatar :size="32" :src="tx" />
          </el-button>
          <el-button class="bu" @click="router.push('/login')" v-if="!isLoggedIn">
            <span class="nav-items-text">登录</span>
          </el-button>
          <el-button class="bu">
            <el-icon class="nav-items-icon"><Setting /></el-icon>
          </el-button>
          <el-button class="bu"  @click="showAdd">
            <el-icon class="nav-items-icon"><CirclePlus /></el-icon>
            <span class="nav-items-text">发贴子</span>
          </el-button>
          <el-button class="bu">
            <el-icon class="nav-items-icon"><HomeFilled /></el-icon>
            <span class="nav-items-text">首页</span>
          </el-button>

          <el-button  class="bu">
            <el-icon class="nav-items-icon"><Star /></el-icon>
            <span class="nav-items-text">热门</span>
          </el-button>

          <el-button class="bu">
            <el-icon class="nav-items-icon"><VideoPlay /></el-icon>
            <span class="nav-items-text">视频</span>
          </el-button>

          <el-button class="bu">
            <el-badge :value="2" :max="99">
              <el-icon class="nav-items-icon" @click="router.push('/notice')"><Message />

              </el-icon>
            </el-badge>
          </el-button>




        </div>
      </el-col>
    </el-row>
  </div>
  <!-- 发布博客 dialog-->
  <el-dialog v-model="addDialogVisible"  width="40%" top="2vh" destroy-on-close>
   <add-post   @closeDialog="addDialogVisible = false">

   </add-post>
  </el-dialog>
</template>

<style scoped>
.navbar-container {
  width: 100%;
  height: 60px;
  background-color: white;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  position: fixed; /* 关键修改：固定定位 */
  top: 0; /* 固定在顶部 */
  left: 0; /* 从左侧开始 */
}

.navbar {
  height: 100%;
  padding: 0 20px;
}

.left-section {
  display: flex;
  align-items: center;
}
.bu{
  border: none;
}
.logo-area {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-text {
  font-weight: bold;
  font-size: 25px;
}

.domain {
  color: #999;
  font-size: 14px;
}

.center-section {
  display: flex;
  justify-content: center;
}

.search-input {
  width: 80%;
}

.right-section {
  display: flex;
  justify-content: flex-end;
}

.nav-items {
  display: flex;
  align-items: center;
  gap: 10px;
}
.nav-items-icon {
  font-size: 22px; /* 增大图标大小 */
  margin-bottom: 2px;
}

.nav-items-text {
  font-size: 14px; /* 增大文字大小 */
  color: #333;
}
.accessibility-btn {
  color: #666;
}
</style>